'''
    第一周作业一  打印9*9乘法表
    用while和 for in 分别输出四种九九乘法表
    @author  宛茹
'''

print('=' * 30, '用for..in输出四种九九乘法表', '=' * 30)

# 用for in 输出九九乘法表一
for i in range(1, 10):
    for j in range(1, i + 1):
        # format占位符，占4位，靠左边用大于
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
    print()

print('-' * 80)

# 用for in 输出九九乘法表二

for i in range(9, 0, -1):
    for j in range(1, i + 1):
        # format占位符，占4位，靠左边用小于
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
    print()

print('-' * 80)

# 用for in 输出九九乘法表三

for i in range(1, 10):
    # 打印空格字符
    n = 9 - i
    print('{:<9}'.format('') * n, end='')

    for j in range(i, 0, -1):
        # format占位符，占4位，靠左边用小于
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
    print()

print('-' * 80)

# 用for in 输出九九乘法表四

for i in range(9, 0, -1):
    # 打印空格字符
    n = 9 - i
    print('{:<9}'.format('') * n, end='')

    for j in range(i, 0, -1):
        # format占位符，占4位，靠左边用小于
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
    print()

print('=' * 30, '用while输出四种九九乘法表', '=' * 30)

# 用while 输出九九乘法表一
i = 1
while i < 10:
    j = 1
    while j <= i:
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
        j = j + 1
    i = i + 1
    print()

print('-' * 80)

# 用while 输出九九乘法表二
i = 9
while i > 0:
    j = 1
    while j <= i:
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
        j = j + 1
    i = i - 1
    print()

print('-' * 80)

# 用while 输出九九乘法表三
i = 1
while i < 10:
    n = 9 - i
    print('{:<9}'.format('') * n, end='')
    j = i
    while j > 0:
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
        j = j - 1
    i = i + 1
    print()

print('-' * 80)

# 用while 输出九九乘法表四
i = 9
while i > 0:
    n = 9 - i
    print('{:<9}'.format('') * n, end='')
    j = i
    while j > 0:
        print('{}*{}={:<4}'.format(j, i, i * j), end=' ')
        j = j - 1
    i = i - 1
    print()
